//index.js
//获取应用实例
// const app = getApp()

// Page({
//   data: {
//     motto: 'Hello World',
//     userInfo: {},
//     hasUserInfo: false,
//     canIUse: wx.canIUse('button.open-type.getUserInfo')
//   },
//   //事件处理函数
//   bindViewTap: function() {
//     wx.navigateTo({
//       url: '../logs/logs'
//     })
//   },
//   onLoad: function () {
//     if (app.globalData.userInfo) {
//       this.setData({
//         userInfo: app.globalData.userInfo,
//         hasUserInfo: true
//       })
//     } else if (this.data.canIUse){
//       // 由于 getUserInfo 是网络请求，可能会在 Page.onLoad 之后才返回
//       // 所以此处加入 callback 以防止这种情况
//       app.userInfoReadyCallback = res => {
//         this.setData({
//           userInfo: res.userInfo,
//           hasUserInfo: true
//         })
//       }
//     } else {
//       // 在没有 open-type=getUserInfo 版本的兼容处理
//       wx.getUserInfo({
//         success: res => {
//           app.globalData.userInfo = res.userInfo
//           this.setData({
//             userInfo: res.userInfo,
//             hasUserInfo: true
//           })
//         }
//       })
//     }
//   },
//   getUserInfo: function(e) {
//     console.log(e)
//     app.globalData.userInfo = e.detail.userInfo
//     this.setData({
//       userInfo: e.detail.userInfo,
//       hasUserInfo: true
//     })
//   }
// })



Page({


  data: {


    tempFilePaths: '',


    hidden: true, //true


    buthidden: false, //false


    sourceType: ['album', 'camera'],

    flag: 0,
    listCategory: [{
        "name": "上门神准时",
        "id": 1
      },
      {
        "name": "服务态度好",
        "id": 2
      },
      {
        "name": "称重准确效率高",
        "id": 3
      },
      {
        "name": "现场清扫整洁",
        "id": 4
      }
    ],

    statusSelect: "", //判断是否选中



    checks: [{
      name: "投影仪",
      value: '0',
      checked: false
    }, {
      name: "电视机",
      value: '1',
      checked: false
    }, {
      name: "空调",
      value: '2',
      checked: false
    }, {
      name: "Wifi",
      value: '3',
      checked: false
    }, {
      name: "电脑",
      value: '4',
      checked: false
    }, {
      name: "舞把杆",
      value: '5',
      checked: false
    }, {
      name: "镜面墙",
      value: '6',
      checked: false
    }, {
      name: "音响",
      value: '7',
      checked: false
    }, {
      name: "桌椅",
      value: '8',
      checked: false
    }, {
      name: "其他",
      value: '9',
      checked: false
    }],
    comment:"您对本次服务满意吗",
    arrayChecks:""
  },


  onLoad: function(options) {


    try {


      var res = wx.getSystemInfoSync()


      var platform = res.platform


      if (platform == 'ios') {


        util.msg("警告", "IOS系统暂不支持拍照，请从相册选择照片")


        this.setData({


          sourceType: ['album']


        })


      }


      console.log(platform)


    } catch (e) {}


  },

  frontimage: function() {


    var _this = this;


    var Type = _this.data.sourceType


    wx.chooseImage({


      count: 1, // 默认9 


      sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有


      sourceType: Type, // 可以指定来源是相册还是相机，默认二者都有 


      success: function(res) {


        // 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片 


        _this.setData({


          FilePaths: res.tempFilePaths


        })


      }


    })


  },


  reciteimage: function() {


    var _this = this;


    var Type = _this.data.sourceType


    wx.chooseImage({


      count: 1, // 默认9 


      sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有 


      sourceType: Type, // 可以指定来源是相册还是相机，默认二者都有 


      success: function(res) {


        // 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片 


        _this.setData({


          recitePaths: res.tempFilePaths


        })

        console.log(_this.data.recitePaths);
      }


    })


  },


  // 监听字数
  bindTextAreaChange: function(e) {
    var that = this
    var value = e.detail.value,
      len = parseInt(value.length);
    if (len > that.data.noteMaxLen)
      return;
    that.setData({
      info: value,
      noteNowLen: len
    })

  },
  // 提交清空当前值
  bindSubmit: function() {
    var that = this;
    wx.showToast({
      title: '发布成功',
      icon: 'success',
      duration: 1500,
      mask: false,
      success: function() {
        that.setData({
          info: '',
          noteNowLen: 0,
          flag: 0
        })
      }
    })
    var checks = that.data.checks;
    var array = new Array;
    for (var i = 0; i < checks.length ;i++){
      if (checks[i].checked == true) {
        array.push(checks[i].name);
      }
    }
    that.setData({ arrayChecks: array})
    console.log(array);
    console.log(that.data.arrayChecks);
   
  },
  changeColor1: function() {
    var that = this;
    that.setData({
      flag: 1,
      checks: [{
        name: "上门不准时",
        value: '0',
        checked: false
      }, {
        name: "服务态度恶劣",
        value: '1',
        checked: false
      }, {
        name: "称重缺斤少两",
        value: '2',
        checked: false
      }, {
        name: "不守信用",
        value: '3',
        checked: false
      }, {
        name: "现场处理邋遢",
        value: '4',
        checked: false
      }, {
        name: "沟通不积极",
        value: '4',
        checked: false
      }],
      comment:"非常不满意 ，各方面都很差"
    });
  },
  changeColor2: function() {
    var that = this;
    that.setData({
      flag: 2,
      checks: [{
        name: "上门不准时",
        value: '0',
        checked: false
      }, {
          name: "服务态度恶劣",
        value: '1',
        checked: false
      }, {
          name: "称重缺斤少两",
        value: '2',
        checked: false
      }, {
          name: "不守信用",
        value: '3',
        checked: false
      }, {
         name: "现场处理邋遢",
        value: '4',
        checked: false
        }, {
          name: "沟通不积极",
          value: '4',
          checked: false
        }],
      comment: "不满意 ，比较差"
    });
  },
  changeColor3: function() {
    var that = this;
    that.setData({
      flag: 3,
      checks: [{
        name: "上门不准时",
        value: '0',
        checked: false
      }, {
        name: "服务态度恶劣",
        value: '1',
        checked: false
      }, {
        name: "称重缺斤少两",
        value: '2',
        checked: false
      }, {
        name: "不守信用",
        value: '3',
        checked: false
      }, {
        name: "现场处理邋遢",
        value: '4',
        checked: false
      }, {
        name: "沟通不积极",
        value: '4',
        checked: false
      }],
      comment:"一般，还需改善"
    });
  },
  changeColor4: function() {
    var that = this;
    that.setData({
      flag: 4,
      checks: [{
        name: "上门不准时",
        value: '0',
        checked: false
      }, {
        name: "服务态度恶劣",
        value: '1',
        checked: false
      }, {
        name: "称重缺斤少两",
        value: '2',
        checked: false
      }, {
        name: "不守信用",
        value: '3',
        checked: false
      }, {
        name: "现场处理邋遢",
        value: '4',
        checked: false
      }, {
        name: "沟通不积极",
        value: '4',
        checked: false
      }],
      comment: "比较满意 ，仍可改善",
    });
  },
  changeColor5: function() {
    var that = this;
    that.setData({
      flag: 5,
      checks: [{
        name: "上门神准时",
        value: '0',
        checked: false
      }, {
        name: "服务态度好",
        value: '1',
        checked: false
      }, {
        name: "称重准确效率高",
        value: '2',
        checked: false
      }, {
        name: "现场清扫整洁",
        value: '3',
        checked: false
      }],
      comment: "非常满意",
    });
  },

  categoryList: function(e) {
    console.log(e);
    var that = this;
    that.setData({ //把选中值放入判断值
      statusSelect: e.currentTarget.dataset.select,
    });
  },

  clicks: function(e) {
    console.log(e);
    console.log(e.currentTarget.dataset.text);
    let index = e.currentTarget.dataset.index;
    let arrs = this.data.checks;
    let array = new Array;
    let text = e.currentTarget.dataset.text;
    if (arrs[index].checked == false) {
      arrs[index].checked = true;
      array.push(text);
    } else {
      arrs[index].checked = false;
    }
    this.setData({
      checks: arrs
    })

    console.log(array);
  },



})